<?php
/***
//自我游订单取消通知(已退款通知)
***/
// include('/var/www/html/new/d/module/api/ZiWoYou/ziwoyou.class.php');
// $zwy = new ZiWoYou();

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$inSide = new SoapClient(null,array(
        "location" => "http://localhost/open/openService/pft_insideMX.php",
        "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);

logfile(json_encode($_REQUEST),'zwy_cancelnote_data');

$order_id = $_REQUEST['order_id'];
$cancel_num = $_REQUEST['cancel_num'];

if($order_id){
	$sel = "select * from all_api_order where apiOrder='$order_id' limit 1";
	$GLOBALS['le']->query($sel);
	if($GLOBALS['le']->fetch_assoc()){
		$pftOrder = $GLOBALS['le']->f('pftOrder');  
		$oStatus = $GLOBALS['le']->f('oStatus');  		
		if($pftOrder && ($oStatus==3 || $oStatus == 4)){
			$response = <<<xml
			<root>
				<result>true</result>
				<msg>接收成功</msg>
			</root>
xml;
			echo $response;
			exit;		
		}
		else{
			$response = <<<xml
				<root>
					<result>false</result>
					<msg>订单状态不是未使用</msg>
				</root>
xml;
			echo $response;
			exit;
		}
	}
	else{
		$response = <<<xml
			<root>
				<result>false</result>
				<msg>无此订单</msg>
			</root>
xml;
		echo $response;
		exit;
	}
}else{
	$response = <<<xml
			<root>
				<result>false</result>
				<msg>请输入有效数据</msg>
			</root>
xml;
	echo $response;
	exit;
}

function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt';
	if(file_exists($filepath)){
		$word = date("Y-m-d H:i:s")."|".$word;
		// $word = mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen('/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt',"a");
			flock($fp, LOCK_EX);
			fwrite($fp,$word."\n");
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}else{
		$fp = fopen('/var/www/html/new/d/logs/api/ZiWoYou/'.$path.'.txt',"a");
		flock($fp, LOCK_EX);
		fwrite($fp,date('Y-m-d H:i:s')."|".$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}
}
?>